var getEare = function(){
    $.ajax({
        url: "/rm/siteInfo/getAll",
        type:"post",
        dataType: 'json',
        // contentType:'application/json',
        data:{'currentPage':1,'pageSize':10},
        success: function(result){
            if(result.status === 0){
                // layer.msg(result.msg);
                console.log(result)
                for (var i = 0;i<result.data.length;i++){
                    var str = `<tr>
                        <td><input type="checkbox"></td>
                        <td curId = "${result.data[i].id}">${i+1}</td>
                        <td><input type="text" value="${result.data[i].troops}"></td>
                        <td><input type="text" value="${result.data[i].startTime}"></td>
                        <td><input type="text" value="${result.data[i].finishTime}"></td>
                        <td><input type="text" value="${result.data[i].developUnit}"></td>
                        <td><input type="text" value="${result.data[i].state}"></td>
                        <td><button onclick="saveEdit(this)">保存</button></td>
                    </tr>`
                    $('tbody').append(str);
                }

                $('.M-box3').pagination({
                    pageTotal: parseInt(result.data.length/10)+1,
                    showData:10,
                    coping: true,
                    prevContent: '<',
                    nextContent: '>',
                    homePage: '首页',
                    endPage: '末页',
                    callback: function (api) {
                        $('tbody').empty();
                        var page = api.getCurrent()
                        $.ajax({
                            url: "/rm/siteInfo/getAll",
                            type:"post",
                            dataType: 'json',
                            data:{'currentPage':page,'pageSize':10},
                            success: function(result){
                                if(result.status === 0){
                                    // layer.msg(result.msg);
                                    console.log(result)
                                    for (var i = 0;i<result.data.length;i++){
                                        var str = `<tr>
                                            <td><input type="checkbox"></td>
                                            <td curId = "${result.data[i].id}">${i+1}</td>
                                            <td><input type="text" value="${result.data[i].troops}"></td>
                                            <td><input type="text" value="${result.data[i].startTime}"></td>
                                            <td><input type="text" value="${result.data[i].finishTime}"></td>
                                            <td><input type="text" value="${result.data[i].developUnit}"></td>
                                            <td><input type="text" value="${result.data[i].state}"></td>
                                            <td><button onclick="saveEdit(this)">保存</button></td>
                                        </tr>`
                                        $('tbody').append(str);
                                    }
                                }else{

                                }
                            }, //处理完成
                            error: function(res){

                            },
                            complete:function(){
                                // layer.close(layerLoad);
                            },
                        });
                    }
                });

            }else{
                console.log(232222)
            }
        }, //处理完成
        error: function(res){

        },
        complete:function(){
            // layer.close(layerLoad);
        },
    });
}

getEare();
var deleteEdit = function(){
    var unshift = '';
    for (let i = 0 ;i<$('tbody :checked').length; i++){
        unshift+=Number($('tbody :checked').eq(i).parent().next().text())
    }
    console.log(unshift);
    $.ajax({
        url: "/rm/siteInfo/removeById",
        type:"post",
        data:{'ids':unshift},
        success: function(result){
            layer.msg(result.msg)
        }, //处理完成
        error: function(res){
            layer.msg(res.msg)
        },
        complete:function(){
            // layer.close(layerLoad);
        },
    });
};

var saveEdit = function(_this){
    var json = {"id":Number($(_this).parent().siblings('td').eq(1).attr('curId')),"troops":$(_this).parent().siblings('td').eq(2).find('input').val(),"startTime":$(_this).parent().siblings('td').eq(3).find('input').val(),"finishTime":$(_this).parent().siblings('td').eq(4).find('input').val(),"developUnit":$(_this).parent().siblings('td').eq(5).find('input').val(),"state":$(_this).parent().siblings('td').eq(6).find('input').val()};
    console.log(json);
    $.ajax({
        url: "/rm/siteInfo/saveSite",
        type:"post",
        data:json,
        success: function(result){
            layer.msg(result.msg)

        }, //处理完成
        error: function(res){
            layer.msg(res.msg)


        },
        complete:function(){
            // layer.close(layerLoad);
        }
    });
};
var exportEare = function () {
    location.href = "siteInfo/exportSite";
}
var importEare = function(){
    layer.open({
        type: 0,//类型,
        title: '请选择导入文件',
        area:[600,480],
        content: '<input type="file" accept=\'.xls,.xlsx\' class="chooseFile" style="color: #0C0C0C"/>',
        btn1:function(){
            $.ajax({
                url: "/rm/siteInfo/importSite",
                type:"post",
                data:$('.chooseFile').val(),
                success: function(result){
                    layer.msg(result.msg)
                    layer.close()
                }, //处理完成
                error: function(res){
                    layer.msg(res.msg)


                },
                complete:function(){
                    // layer.close(layerLoad);
                }
            });
        }
    });

}
